package io.renren.modules.avanotes.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.vo.ReferenceMaterialVo;
import io.renren.common.vo.input.KeywordDetailVo;
import io.renren.modules.avanotes.entity.ClassifySubjectEntity;
import io.renren.modules.avanotes.entity.FormworkEntity;
import io.renren.modules.avanotes.entity.LocalMarkdownNotesEntity;
import io.renren.modules.avanotes.service.ClassifySubjectService;
import io.renren.modules.avanotes.service.FormworkService;
import io.renren.modules.avanotes.service.LocalMarkdownNotesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 模板表
 *
 * @author zzr
 * @email 529742454@qq.com
 * @date 2022-02-21 18:11:05
 */
@RestController
@RequestMapping("avanotes/formwork")
@Api("模板表接口")
public class FormworkController {
    @Autowired
    private FormworkService formworkService;

    /**
     * 由于前端选择器没有分页的触发，所以接口就列出所有数据
     * @param keyword
     * @return
     */
    @PostMapping("/list4select/{keyword}")
    @ApiOperation("搜索模板关键词")
    public R list4select( @PathVariable("keyword") String keyword) {
        List<FormworkEntity> list = formworkService.list4SelectByTitle(keyword);

        //return R.ok().put("page", page);
        return R.ok().setData(list);
    }

    /**
     * 列表
     */
    @PostMapping("/list")
    //@RequiresPermissions("avanotes:formwork:list")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "limit", value = "每页记录数", paramType = "query", dataType = "String"),
    //        @ApiImplicitParam(name = "key", value = "检索关键字", paramType = "query", dataType = "String")
    //})
    //@ApiOperation("查询列表")
    public R list(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = formworkService.queryPage(params);

        //return R.ok().put("page", page);
        return R.ok().setData(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("avanotes:formwork:info")
    //@ApiOperation("查询单条")
    public R info(@PathVariable("id") String id) {
            FormworkEntity formwork = formworkService.getById(id);

        //return R.ok().put("formwork", formwork);
        return R.ok().setData(formwork);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("avanotes:formwork:save")
    //@ApiOperation("保存")
    public R save(@RequestBody FormworkEntity formwork) {
            formworkService.save(formwork);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("avanotes:formwork:update")
    //@ApiOperation("修改")
    public R update(@RequestBody FormworkEntity formwork) {
            formworkService.updateById(formwork);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("avanotes:formwork:delete")
    //@ApiOperation("删除")
    public R delete(@RequestBody String[] ids) {
            formworkService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
